// pages/tool/doc/document.js
const app = getApp();
Page({
    /**
     * 组件的属性列表
     */
    properties: {},

    /**
     * 组件的初始数据
     */
    data: {
        dataList: '',
        showShare: false,
        itemTile: '',
        shareTitle: '',
        id: ''


    },
    onShow: function () {
        this.myinfos();
    },
    myinfos() {
        app.func.getPromise('/my/info')
            .then(([code, res]) => {
                this.setData({
                    myinfo: res.message
                }, () => {
                    this.cardList(res.message.type);
                });
            })
    },
    cardList(type) {
        if (type == 1 || type == 3) {
            app.func.getPromise('/document/list')
                .then(([code, res]) => {
                    if (code == 200) {
                        console.log(res.data)
                        this.setData({dataList: res.data});
                    }
                })
        } else {
            app.func.getPromise('/document/favouriteList')
                .then(([code, res]) => {
                    if (code == 200) {
                        console.log(res.data.id)
                        this.setData({dataList: res.data});
                    }
                })
        }

    },
    showShare(e) {
        let item = e.currentTarget.dataset.item;
        this.setData({
            shareInfo: item,
            showShare: true,
            shareTitle: item.name + ',请查收！'
        })
    },
    cancelShare() {
        this.setData({
            showShare: false
        })
    },
    getInputValue(e) {
        this.setData({
            shareTitle: e.detail.value
        });
    },
    viewPath(e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: `/tools/pages/tool/docs/detail/detail?id=${id}`,
        })
    },
    openy(e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({url: "./preview/preview?id=" + id})
    },

    /**
     * 分享的内容
     */
    onShareAppMessage: function () {
        return {
            title: this.data.shareTitle, //文字
            imageUrl: `https://files.dianlinet.com/dianli/images/2020-10-29/16-46-42.jpg`, //图片
            path: `/tools/pages/tool/docs/detail/detail?id=${this.data.shareInfo.id}` //打开的页面
        }
    },
    //https://files.dianlinet.com/dianli/images/2020-10-29/16-46-42.jpg
    /**
     * 组件的方法列表
     */
    methods: {}
})
